home *** CD-ROM | disk | FTP | other *** search
- /***************************************************************************
- * EXAMPL7.C
- * Simple graphics demo
- * ****************************************************************************/
- #ifdef NOWINDOWS
- #include "e:\include\graph.h"
- #include "e:\include\stdio.h"
- #include "e:\include\conio.h"
- #include "e:\include\stdlib.h"
- #include "e:\include\memory.h"
- #include "e:\include\math.h"
- #include "e:\include\string.h"
- #else
- #include <Windows.h>
- #include "WinDosIO.h"
- long far pascal WndProc(HWND, WORD, WORD, LONG);
- HWND idWindow;
- HANDLE hInst;
- #include <stdlib.h>
- #include <memory.h>
- #include <alloc.h>
- #include <math.h>
- #include <string.h>
- #endif
-
-
-
- char buffer[80];
- int i,j;
-
-
-
- #ifdef NOWINDOWS
- main()
- {
- #else
- int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance,
- LPSTR lpszCmdline, int cmdshow)
-
- {
- HWND hwnd;
- MSG msg;
- WNDCLASS wc;
- RECT r;
-
- /* Register Main Window Class */
-
- hInst = hInstance;
-
- if (!hPrevInstance)
- {
- wc.style = 0;
- wc.lpfnWndProc = WndProc;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.hInstance = hInstance;
- wc.hIcon = LoadIcon( 0, IDI_APPLICATION );
- wc.hCursor = LoadCursor( 0, IDC_ARROW );
- wc.hbrBackground = COLOR_WINDOW + 1;
- wc.lpszMenuName = "Example5";
- wc.lpszClassName = "Example5";
- RegisterClass( &wc );
- }
-
-
- /* Initialize terminal IO */
- WinDosIO(WD_INIT,hInstance,0);
-
- /* Create Main Window */
- hwnd = CreateWindow(
- "Example5",
- "A Graphics Demo",
- WS_OVERLAPPEDWINDOW,
- CW_USEDEFAULT,
- 0,
- CW_USEDEFAULT,
- 0,
- 0,
- 0,
- hInstance,
- NULL
- );
-
- ShowWindow(hwnd, cmdshow);
-
- /* Create menu window */
- r.top = 0;
- r.left = 0;
- idWindow = CreateWindow("termIO","Graphic Window",
- WS_CHILD ,
- r.left,r.top,640,480,
- hwnd,20,hInstance,0);
- ShowWindow(idWindow,SW_SHOW);
- UpdateWindow(idWindow);
- #endif
-
- {
- struct POINTS {
- long x;
- long y;
- } points[5] =
- {{0,0},{620L<<10,0},{620L<<10,420L<<10},
- {0,420L<<10},{0,0}};
-
- short ratio, times;
-
- do {
- printf("Enter ratio 1-1023 :");
- gets(buffer);
- ratio = atoi(buffer);
- } while (ratio < 1 || ratio > 1023);
-
- printf("Enter number of times to spiral :");
- gets(buffer);
- times = atoi(buffer);
-
- if (_setvideomode(_ERESCOLOR) == 0)
- {
- exit(0);
- }
-
-
- _clearscreen(_GCLEARSCREEN);
- _moveto(0,0);
- for (i = 0; i < times; i++)
- {
- _setcolor((i & 3) + 1);
- _lineto((short)(points[1].x >> 10),
- (short)(points[1].y >> 10));
- points[4].x = points[0].x +
- (((points[1].x - points[0].x) * ratio) >> 10);
- points[4].y = points[0].y +
- (((points[1].y - points[0].y) * ratio) >> 10);
- for (j = 0; j < 4; j++)
- points[j] = points[j + 1];
- }
-
- for(;;)
- {
- char c;
- if (((c = getch()) == EOF) || c == 'q') break;
- setpalette(1,random(15)+1);
- setpalette(2,random(15)+1);
- setpalette(3,random(15)+1);
- setpalette(4,random(15)+1);
- }
- WinDosIO(WD_DESTROY,hwnd,0);
- while( GetMessage( &msg, 0, 0, 0 ) != 0 )
- {
- TranslateMessage( &msg );
- DispatchMessage( &msg );
- }
- return 0;
- }
- }
- #ifdef NOWINDOWS
- #else
- long far pascal WndProc(HWND hwnd, WORD msg, WORD wParam, LONG lParam)
- {
-
- switch( msg )
- {
- case WM_COMMAND:
- break;
- case WM_SETFOCUS:
- WinDosIO(WD_SETFOCUS,0,0);
- break;
- case WM_CLOSE:
- WinDosIO(WD_DESTROY,hwnd,0);
- return 0;
- case WM_DESTROY:
- PostQuitMessage(0);
- return 0;
- }
-
- return DefWindowProc(hwnd,msg,wParam,lParam);
- }
-
- #endif
-